<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<script src="../../libs/js/mui.min.js"></script>
		<style type="text/css">
			#bcid {
				width: 100%;
				height: 100%;
				position: absolute;
				background: #000000;
			}
			html,
			body,
			div {
				height: 100%;
				width: 100%;
			}
			
			.fbt {
				color: #0E76E1;
				width: 50%;
				background-color: #ffffff;
				float: left;
				line-height: 44px;
				text-align: center;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="background-color: #ffffff;">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" style="color: #0E76E1;">扫一扫</h1>
		</header>

		<div id="bcid">
			<!--盛放扫描控件的div-->
		</div>

		<script type="text/javascript">
			var height = window.innerHeight + 'px'; //获取页面实际高度   
			var width = window.innerWidth + 'px';
			document.getElementById("bcid").style.height = height;
			document.getElementById("bcid").style.width = width;
			scan = null; //扫描对象   
			mui.plusReady(function() { //通过mui初始化扫描 
				mui.init();
				startRecognize();
			});

			function startRecognize() { //开启扫描 
				try {
					var filter;
					var styles = {
						frameColor: "#29E52C",
						scanbarColor: "#29E52C",
						background: ""
					}
					//扫描控件构造   
					scan = new plus.barcode.Barcode('bcid', filter, styles);
					scan.onmarked = onmarked;
					scan.onerror = onerror; //扫描错误 
					scan.start();
					var flag = false;
				} catch(e) {
					alert("出现错误啦:\n" + e);
				}
			};

			function onerror(e) { //错误弹框 
				alert(e);
			};

			function onmarked(type, result) { //这个是扫描二维码的回调函数，type是扫描二维码回调的类型 
				var text = '';
				switch(type) { //QR,EAN13,EAN8都是二维码的一种编码格式,result是返回的结果 
					case plus.barcode.QR:
						text = 'QR: ';
						break;
					case plus.barcode.EAN13:
						text = 'EAN13: ';
						break;
					case plus.barcode.EAN8:
						text = 'EAN8: ';
						break;
				}
				alert(text + " : " + result);
			};
		</script>
	</body>

</html>